package com.aaa.dem1101;

/**
 * @Author: whj
 * @Version 1.0
 * @Date: 2022/11/1  13:10
 */
public class Yield {
    public static void main(String[] args) {
        YieldDemo demo = new YieldDemo();
        YieldDemo demo1 = new YieldDemo();
        demo.start();
        demo1.start();
    }
}
class YieldDemo extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            //当前线程放弃时间片，进入就绪状态，参与下次cpu时间片的竞争。可能出现交替的频率比较高
            Thread.yield();
            System.out.println(Thread.currentThread().getName()+"***"+i);
        }
    }
}
